package com.asia5b.a5mall.member.activity.comment

import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.asia5b.a5bmall.resource.ActCons
import com.asia5b.a5mall.member.R
import com.asia5b.a5mall.member.databinding.ActivityCommentdetailBinding
import com.asia5b.a5mall.middleware.base.SimpleActivity
import com.asia5b.a5mall.middleware.logic.viewmodel.member.CommentDetailActivityVM
import com.asia5b.a5mall.middleware.model.member.CommentsModel
import com.asia5b.a5mall.middleware.model.shop.AbsShopModel
import com.asia5b.a5mall.middleware.utils.WImageLoader
import com.asia5b.a5mall.middleware.utils.WTimeUtils
import kotlinx.android.synthetic.main.activity_commentdetail.*
/**
 * Created by zhangyuncai on 2019/12/21.
 * @Note   评价详情
 */
@Route(path = ActCons.CommentDetailActivity)
class CommentDetailActivity : SimpleActivity<CommentDetailActivityVM, ActivityCommentdetailBinding>() {

    override val viewModelClazz: Class<CommentDetailActivityVM>
        get() = CommentDetailActivityVM::class.java

    override fun getDataBinding(): ActivityCommentdetailBinding {
        return ActivityCommentdetailBinding.inflate(layoutInflater)
    }

    override var sIsDark = true
    var comment_id: Int = 0
    override fun initData() {

    }

    override fun initView() {
        comment_id = intent.getIntExtra("id", 0)
        mViewModel.getCommentDetail(comment_id)
    }

    override fun initEvent() {
    }

  override fun startObserver()
    {
        mViewModel.getCommentDetailResultLiveData.observe(this, Observer {
            getCommentDetailResult(it)
        })
        mViewModel.getShopResultLiveData.observe(this, Observer {
            getShopResult(it)
        })
    }

     fun getCommentDetailResult(commentsModel: CommentsModel?) {
        commentsModel?.run {
            mDataBinding.model = this

            //第一次评价时间
            val time = WTimeUtils.format("${this.create_time * 1000}", WTimeUtils.text_yyyy_MM_dd_HH_mm_ss)
            tv_commentdetail_firsttime.text=time
        }
    }

     fun getShopResult(shopDetailModel: AbsShopModel) {

        shopDetailModel.run {
            //店铺图片
            WImageLoader.displayImage(absShopLogo, iv_commentdetail_shoplogo, R.drawable.img_default)
            //店铺名称
            iv_commentdetail_shopname.text = absShopName
            //店铺评分
            rb_commentdetail_shop_star.rating = absShopCredit.toFloat()
            //店铺评分值
            iv_commentdetail_starvalue.text = String.format("%.1f", absShopCredit)

            //描述相符
            rb_shop_descstar.rating = absShopDescCredit.toFloat()
            tv_shop_descstar.text = String.format("%.1f", absShopDescCredit.toFloat())
            //物流相符
            rb_shop_expressstar.rating = absShopDeliveryCredit.toFloat()
            tv_shop_expressstar.text = String.format("%.1f", absShopDeliveryCredit.toFloat())
            //服务相符
            rb_shop_serverstar.rating = absShopServiceCredit.toFloat()
            tv_shop_serverstar.text = String.format("%.1f", absShopServiceCredit.toFloat())
        }
    }


}